package it.softphone.cmc.server.pojosr;

import java.util.List;

import org.apache.commons.vfs.FileObject;

import com.newatlanta.commons.vfs.provider.gae.GaeClassLoader;
import com.newatlanta.commons.vfs.provider.gae.jar.GaeJarFileSystem;

import de.kalpatec.pojosr.framework.launch.BundleDescriptor;
import de.kalpatec.pojosr.framework.launch.ClasspathScanner;

public class GaeClasspathScanner extends ClasspathScanner {

	@Override
	public List<BundleDescriptor> scanForBundles(String filterString, ClassLoader loader) throws Exception {
		
		final java.util.List<BundleDescriptor> bundles = super.scanForBundles(filterString, loader);
		
		if( loader instanceof GaeClassLoader ) {
			final GaeClassLoader cl = (GaeClassLoader) loader;
			for( FileObject fo : cl.resources ) {
				bundles.add( new BundleDescriptor(cl, fo.getURI(), ((GaeJarFileSystem)fo.getFileSystem()).getManifest() ));
			}
		}
		
		return bundles;
	}


}
